﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace homeworkhero
{
    public class Animation
    {
        String name;
        Texture2D[] textures;
        int currTexture;
        TimeSpan currentTime;
        TimeSpan duration;
        bool oneTime;
        bool running = true;

        public Animation(String name, Texture2D[] textures, TimeSpan duration, bool oneTime) {
            this.name = name;
            this.textures = textures;
            currTexture = 0;
            this.currentTime = TimeSpan.Zero;
            this.duration = duration;
            this.oneTime = oneTime;
        }

        public Vector2 getDimensions() {
            return new Vector2(textures[0].Width, textures[0].Height);
        }

        public String getName() {
            return name;
        }

        public int getCurrTexture() {
            return currTexture;
        }

        public int getNumOfTextures() {
            return textures.Length;
        }

        public void progress(GameTime time) {
            currentTime += time.ElapsedGameTime;
            currTexture = (int)Math.Floor((double)currentTime.Ticks * getNumOfTextures() / duration.Ticks);
            if(oneTime && currTexture >= getNumOfTextures()) {
                running = false;
            }
            currTexture %= getNumOfTextures();
        }

        public Texture2D getTexture() {
            return textures[currTexture];
        }

        public bool isStopped() {
            if (!oneTime)
                return false;
            else
                return !running;

        }

        public Animation copy() {
            return new Animation(this.name, this.textures, this.duration, this.oneTime);
        }
    }
}
